/**
 * Copyright (c) 2010-2011 Pierre Labatut
 *
 * This file is part of Space-Chronicles project.
 *
 * Space-Chronicles is free software: you can redistribute it and/or modify it
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or <http://code.google.com/p/space-chronicles/>.
 */
package space.app.common;

import javax.media.opengl.GLEventListener;
import javax.swing.SwingUtilities;
import space.annotation.EventThreadConfined;
import space.debug.DbgGL;

/**
 *
 * @author Pierre
 */
public abstract class AbstractRender<E extends GLEventListener>  {

    final protected E eventListner;
    final protected JOGLPanel panel;

    public AbstractRender(E eventListner, JOGLPanel pannel) {
        this.eventListner = eventListner;
        this.panel = pannel;
    }

    @EventThreadConfined
    abstract protected void buildCanvas();

    public void initialize() { 
        final Thread thread = new Thread(new Runnable() {

            public void run() {
                //This code runs in a background thread                
                DbgGL.initSingleton();
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        buildCanvas();
                    }
                });
            }
        });
        thread.start();
    }
}
